package com.jhgk.jhcee.forecast.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jhgk.jhcee.bfk.mapper.MPreMajorScoreZjbExportMapper;
import com.jhgk.jhcee.bfk.model.MPreMajorScoreZjbExport;
import com.jhgk.jhcee.bfk.model.MPreMajorScoreZjbExportExample;
import com.jhgk.jhcee.common.enums.BasisResultEnum;
import com.jhgk.jhcee.common.resultful.BasisResultful;
import com.jhgk.jhcee.common.resultful.PageResultful;
import com.jhgk.jhcee.forecast.domain.model.MPreMajorScoreZjbExportMode;
import com.jhgk.jhcee.forecast.service.MPreMajorScoreZjbExportService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: xiezhongping
 * @description:
 * @date: 2021/8/10 15:51.
 */
@Service(value = "MPreMajorScoreZjbExportServiceImpl")
public class MPreMajorScoreZjbExportServiceImpl implements MPreMajorScoreZjbExportService {

    @Autowired
    MPreMajorScoreZjbExportMapper mPreMajorScoreZjbExportMapper;

    @Override
    public PageResultful<PageInfo<MPreMajorScoreZjbExport>> searchAllPage(MPreMajorScoreZjbExportMode mPreMajorScoreZjbExportMode) {
        if (null == mPreMajorScoreZjbExportMode) {
            return PageResultful.fail(BasisResultEnum.PARAM_IS_NULL);
        }
        MPreMajorScoreZjbExportExample example = new MPreMajorScoreZjbExportExample();
        MPreMajorScoreZjbExportExample.Criteria criteria = example.createCriteria();
        criteria.andProvinceUuidEqualTo(mPreMajorScoreZjbExportMode.getProvinceUuid());
        criteria.andYearEqualTo(mPreMajorScoreZjbExportMode.getYear());
        PageHelper.startPage(mPreMajorScoreZjbExportMode.getPage(), mPreMajorScoreZjbExportMode.getLimit());
        List<MPreMajorScoreZjbExport> mPreMajorScoreZjbExports = mPreMajorScoreZjbExportMapper.selectByExample(example);
        if (mPreMajorScoreZjbExports.isEmpty()) {
            return PageResultful.fail(BasisResultEnum.QUERY_IS_NULL);
        }
        PageInfo<MPreMajorScoreZjbExport> pageInfo = new PageInfo<>(mPreMajorScoreZjbExports);
        return PageResultful.success(pageInfo);
    }

    @Override
    public BasisResultful<Object> searchTotal(String provinceUuid, Integer year) {
        if (StringUtils.isBlank(provinceUuid) || null == year) {
            return BasisResultful.fail(BasisResultEnum.PARAM_IS_NULL);
        }
        MPreMajorScoreZjbExportExample example = new MPreMajorScoreZjbExportExample();
        MPreMajorScoreZjbExportExample.Criteria criteria = example.createCriteria();
        criteria.andProvinceUuidEqualTo(provinceUuid);
        criteria.andYearEqualTo(year);
        PageHelper.startPage(1,1);
        List<MPreMajorScoreZjbExport> mPreMajorScoreZjbExports = mPreMajorScoreZjbExportMapper.selectByExample(example);
        if (mPreMajorScoreZjbExports.isEmpty()) {
            return BasisResultful.fail(BasisResultEnum.QUERY_IS_NULL);
        }
        PageInfo<MPreMajorScoreZjbExport> pageInfo = new PageInfo<>(mPreMajorScoreZjbExports);
        return BasisResultful.success(pageInfo.getTotal());
    }
}
